home *** CD-ROM | disk | FTP | other *** search
- /******************************************************/
- /* FstEdC.c .. also A, B, 1, 2, & .h */
- /* */
- /* max_test .. test for MAX_TEXT approaching */
- /* open_to_buff ..open file to new buff_hndl */
- /* set_windows .. set and retrieve from windows menu */
- /******************************************************/
- #include <FstEd.h>
-
- /************************************************/
- /* max_test .. test for MAX_TEXT approaching: */
- /* alert user every dozen strokes if length is */
- /* within MAX_WARN of MAX_TEXT */
- /************************************************/
- max_test (node)
- struct win_node *node;
- {
- char str [LINE_LNGTH], str2 [LINE_LNGTH];
- int length_left;
-
- length_left = MAX_TEXT - (*node->te_hndl)->telength;
- if ( (length_left < MAX_WARN && node->strokes > 11)
- || length_left <= 0
- )
- { if (node->strokes) node->strokes = 1;
- itoa ( (long) (*node->te_hndl)->telength, str);
- itoa (MAX_TEXT, str2);
- paramtext (str, str2, "", "");
- notealert (SIZE_ALRT, NIL);
- }
- if (length_left <= 0) return KLOSE;
- return OK;
- }
-
- /************************************************/
- /* open_to_buff .. open file to new buff_hndl */
- /* create buff_hndle of length lngth and fill */
- /* with file title from vref */
- /************************************************/
- open_to_buff (title, vref, buff_hndl, lngth)
- char *title;
- int vref;
- handle *buff_hndl;
- long *lngth;
- {
- int ref_num;
- char str [LINE_LNGTH], str2 [LINE_LNGTH];
-
- if (fsopen (title, vref, &ref_num) != noerr) return ERR;
- geteof (ref_num, xlngth);
- if (*lngth > MAX_TEXT )
- { fsclose (ref_num);
- itoa (*lngth, str);
- itoa (MAX_TEXT, str2);
- paramtext (str, str2, "", "");
- notealert (SIZE_ALRT, NIL);
- return ERR;
- }
-
- if (!mem_check (*lngth) )
- { fsclose (ref_num); return ERR; }
- *buff_hndl = newhandle (*lngth);
- fsread (ref_num, lngth, **buff_hndl);
- fsclose (ref_num);
- return OK;
- }
-
- /*****************************************************/
- /* set_windows .. set and retrieve from windows menu */
- /* bring choosen window to the front unless command */
- /* is down, in which case, insert window contents */
- /*****************************************************/
- set_windows (node, event, menus, item)
- struct win_node *node;
- eventrecord event;
- menuhandle menus [];
- int item;
- {
- int i;
- windowptr nxt_wp;
- long refcon, lngth;
- static windowptr menu_wp [MAX_ITEMS];
- struct win_node *sel_node;
- tehandle te_hndl;
- char *text, str [LINE_LNGTH], str2 [LINE_LNGTH];
-
- if (item > 0)
- { if (!(event.modifiers & cmdkey) )
- return selectwindow (menu_wp [item - 1]);
-
- refcon = ( (windowpeek) menu_wp [item - 1])->refcon;
- sel_node = (struct win_node *) refcon;
-
- paramtext (sel_node->title, node.title, "","");
- i = cautionalert (INSRT_ALRT, NIL);
- if (i != OK) return ERR;
-
- text = *(*sel_node->te_hndl)->htext;
- lngth = (*sel_node->te_hndl)->telength;
-
- if ( !mem_check (lngth) ||
- lngth + (*node->te_hndl)->telength > MAX_TEXT
- )
- { itoa (lngth + (*node->te_hndl)->telength, str);
- itoa (MAX_TEXT, str2);
- paramtext (str, str2, "", "");
- notealert (SIZE_ALRT, NIL);
- return ERR;
- }
- teinsert (text, lngth, node->te_hndl);
- sel_scroll (NIL, NIL, node);
- node->strokes++;
- return OK;
- }
-
- deletemenu (WINDOWS); /* reset menu: */
- disposemenu (menus [WINDOWS]);
- menus [WINDOWS] = newmenu (WINDOWS, "windows");
-
- for (i = 0; i < MAX_ITEMS; )
- { nxt_wp = ( (windowpeek) node->wp)->nextwindow;
- if (nxt_wp == NIL) break;
- if ( ( (windowpeek) nxt_wp)->windowkind != userkind)
- { nxt_wp = ( (windowpeek) node->wp)->nextwindow;
- continue;
- }
-
- refcon = ( (windowpeek) nxt_wp)->refcon;
- node = (struct win_node *) refcon;
- appendmenu (menus [WINDOWS], node->title);
- menu_wp [i++] = node->wp;
- }
- if (i == 0) appendmenu (menus [WINDOWS], "(empty");
- insertmenu (menus [WINDOWS], FONT);
- }
-
-